package com.demo.apparel.controller.uniapp;

import com.demo.apparel.common.Result;
import com.demo.apparel.entity.Agreement;
import com.demo.apparel.service.uniapp.WxAgreementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx/agreement")
@Tag(name = "同意协议接口", description = "协议信息")
public class WxAgreementController {

    private final WxAgreementService wxAgreementService;

    public WxAgreementController(WxAgreementService wxAgreementService) {
        this.wxAgreementService = wxAgreementService;
    }

    @GetMapping("/active")
    @Operation(summary = "获取当前生效的协议")
    public Result<Agreement> getActiveAgreement() {
        Agreement activeAgreement = wxAgreementService.getActiveAgreement();
        return Result.success(activeAgreement);
    }

    @GetMapping("/list")
    public List<Agreement> getAllAgreements() {
        return wxAgreementService.getAllAgreements();
    }

    @PostMapping("/setActive/{id}")
    public String setActive(@PathVariable String id, @RequestParam boolean active) {
        wxAgreementService.setActive(id, active);
        return active ? "已启用" : "已停用";
    }
}